import os  # 用于文件和文件夹操
import re
def get_dirs_from_folder(folder_path):
    files = os.listdir(folder_path)
    dirs = []
    for file in sorted(files):
        if os.path.isdir(os.path.join(folder_path,file)):
            dirs.append(file)
    # 返回完整的文件路径
    return dirs

def get_files_from_folder(folder_path):
    files = os.listdir(folder_path)
    filelist = []
    for file in files:
        if os.path.isfile(folder_path + r"\\" + file):
            filelist.append(file)
    # 返回完整的文件路径
    return filelist


def get_all_files(directory):
    file_list = []
    for root, dirs, files in os.walk(directory):
        for file in files:
            file_path = os.path.join(root, file)
            file_list.append(file_path)
    return file_list


def get_all_files_by_type(directory, file_type):
    file_list = []
    for root, dirs, files in os.walk(directory):
        files.sort(key=extract_number)  # 找出字符串中的数字并依据其整形进行排序
        for file in files:
            file_path = os.path.join(root, file)
            if file_type in file_path:
                file_list.append(file_path)
    return file_list

def extract_number(filename):
    matches = re.findall(r'\d+', filename)
    if matches:
        return int(matches[0])
    else:
        return float('inf')  # 如果没有数字，返回一个很大的数，这样没有数字的文件名会排在最后

if __name__ == '__main__':

    # 指定目录下文件输出
    path = r"D:\data\RegularNovel\进化的四十六亿重奏"
    files = get_all_files(path)

    for file in files:
        file = file.replace('D:\\data\\RegularNovel\\进化的四十六亿重奏\\','').replace('.txt','')
        print('\'' + file + '\',')

    # 指定目录下文件夹输出
    path = r"D:\data\tmp"
    for item in get_dirs_from_folder(path):
        print(item)

    # path = r"H:\005_Data\牛人必备的100个思维模型"
    # for item in get_all_files_by_type(path,'.mp4'):
    #     # print('\''+item+'\',')
    #     print(item)